/*************************************************************************** 
 * 
 *		EDROOM SERVICE LIBRARY   
 *    
 *		Copyright (C) 2007-2010  Oscar Rodriguez Polo  
 * 
 *      Contact: opolo@aut.uah.es  
 * 
 ****************************************************************************/

/**************************************************************************** 
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation; either version 2 
 *   of the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 *
 *
 ****************************************************************************/

/*!
 * \brief edroom services library header
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-02-15 10:09:39 $
 * \Version $Revision: 1.1.4.2 $
 */

#ifndef __EDROOM_SERVICE_LIBRARY_H
#define __EDROOM_SERVICE_LIBRARY_H

#ifdef CONFIG_OS_RTEMS
#include <rtems.h>
#endif
#include <public/edroombp.h>
#include <public/edroomsl_types.h>
#include <edroomsl/edroomtc.h>
//#include <public/debug_primitives.h>


/*!
 * \brief edroommemory header (edroom services library) 
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-03-04 09:08:17 $
 * \Version $Revision: 1.1.4.5 $
 * 
 * $Log: edroommemory.h,v $
 * Revision 1.1.4.5  2010-03-04 09:08:17  opolo
 * Changed the names of the attributes
 *
 * Revision 1.1.4.4  2010-02-15 10:08:11  opolo
 * actualizados los nombres de los archivos y servicios
 *
 * Revision 1.1.4.3  2006/11/09 15:20:55  opolo
 * Rename of the classes that manage the pools as
 * 	EDROOMPool EDROOMMemoryPool and EDROOMProtectedMemoryPool
 *
 * Revision 1.1.4.2  2006/10/18 18:31:51  opolo
 * Add Log
 *
 *
 * Revision 1.1.4.1  2006/10/18 18:07:20  opolo
 * *** empty log message ***
 * 
 */



#ifndef __EDROOMMemory_H
#define __EDROOMMemory_H



/*!
 * \class CEDROOMPool
 * \brief Virtual base class used to support different kind of pools  
 * 
 * \author Oscar Rodriguez Polo
 */

class CEDROOMPool{
	
	public:

    /*!
     * This function give back an element to the pool .
     * \param pData pointer to the element
     *
     * \return  0 only if there is none error. 
     */

	virtual TEDROOMInt8 FreeData(void * pData)=0;

    /*!
     * Destructor, only to avoid warnings
	*/
	virtual ~CEDROOMPool(){};

	virtual TEDROOMUInt32 GetElementSize(void) = 0;

};

/*!
 * \class CEDROOMMemoryPool
 * \brief This class defines memory pools that emulate dynamic memory in EDROOM. 
 *        The maximun number of elements of the pool is 2?-1 
 * 
 * \author Oscar Rodriguez Polo
 */


class CEDROOMMemoryPool : public CEDROOMPool {

  protected:

  //!Stores the number of elements 
   /* 
   * Maximun number of elements = 2-1 
   */
  TEDROOMUInt32 Dimension; 

  //! True if Pool is empty
  TEDROOMBool Empty; 

  //! Pointer to the Data Memory 
  TEDROOMByte   * PDataMemory;

  //! Size of each element of the pool
  TEDROOMUInt32 ElementSize;

  //!Array for marking which elements are free 
  TEDROOMBool * PFreeMarks;    

  //!Index to the next free element. 
  /*!
   * If this index is equal to UINT_MAX,
   * there is not free elements
   */
  
  TEDROOMUInt32 NextFreeIndex;	 

 
  public:

  TEDROOMUInt32 GetElementSize(void);


  /*!
   * Set the memory of the pool 
   * \param dimension defines the pool dimension
   * \param pPoolMemory pointer to the data memory pool
   * \param pMarksMemory pointer to the memory that stores the free marks
   * \param elementSize size of each element of the pool 
   */

  void SetMemory(TEDROOMUInt32 dimension
  					, void * pPoolMemory
  					, TEDROOMBool * pMarksMemory
  					, TEDROOMUInt32 elementSize);


  /*!
   * Allocation of a free element,
   * \return a pointer to the element or NULL if none element is available
   */

	TEDROOMByte * AllocData(void);

  /*!
   * Allocation of a free element,
   * \param rElemIndex reference to the index of the element, modified by this
   * 				  method
   * \return a pointer to the element or NULL if none element is available
   */

	TEDROOMByte * AllocData(TEDROOMUInt32& rElemIndex);


    /*!
     * This function give back an element to the pool and marks it as free.
     * \param pData pointer to the element
     *
     * \return  0 only if there is none error. 
     * 			-1 if the element does not allow to this pool
     * 			-2 if the element was free
     */

	TEDROOMInt8 FreeData(void * pData);


    /*!
     * This function checks when the pool is empty.
     *
     * \return true only if the pool is empty.
     */

	TEDROOMBool IsEmpty(){return NextFreeIndex==EDROOMUINT32_MAX;}

    /*!
     * Destructor, only to avoid warnings
	*/
	~CEDROOMMemoryPool(){}


};


/*!
 * \class CEDROOMProtectedMemoryPool
 * \brief This class defines memory pools that emulate dynamic memory in EDROOM. 
 *	The pool is protected in order to be accessible from different Components		
 *  The maximun number of elements of the pool is 2-1 
 * 
 * \author Oscar Rodriguez Polo
 */



class CEDROOMProtectedMemoryPool:public CEDROOMMemoryPool
{
  private:

	//!Semaphore for Mutual Exclusion
	Pr_SemaphoreRec Mutex; 


  public:

	CEDROOMProtectedMemoryPool();

	/*!
    * The constructor set the memory of the pool 
    * \param dimension defines the pool dimension
   * \param pDataMemory pointer to the data memory pool
   * \param pMarksMemory pointer to the memory that stores the free marks
    * \param elementSize size of each element of the pool 
    */
	CEDROOMProtectedMemoryPool(TEDROOMUInt32 dimension
							, void * pDataMemory
							, TEDROOMBool * pMarksMemory
							, TEDROOMUInt32 elementSize);

	/*!
    * Allocation of a free element using mutex 
    * \return a pointer to the element or NULL if none element is available
    */

	TEDROOMByte * AllocData(void);


    /*!
    * Allocation of a free element using mutex
    * \param rElemIndex reference to the index of the element, modified by this
    * 				  method
    * \return a pointer to the element or NULL if none element is available
    */

	TEDROOMByte * AllocData(TEDROOMUInt32& rElemIndex);


    /*!
     * This function give back an element to the pool and marks it as free.
	 * The operation is done in mutual exclusion 
     * \param pData pointer to the element
     *
     * \return  0 only if there is none error. 
     * 			-1 if the element does not allow to this pool
     * 			-2 if the element was free
     */

	TEDROOMInt8 FreeData(void * pData);


    /*!
     * Destructor, only to avoid warnings
	*/
	~CEDROOMProtectedMemoryPool(){}

};



#endif




/*!
 * \brief edroomtypes header (edroom services library) 
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-03-04 09:08:17 $
 * \Version $Revision: 1.1.2.2 $
 *
 * $Log: edroomsl_types.h,v $
 * Revision 1.1.2.2  2010-03-04 09:08:17  opolo
 * Changed the names of the attributes
 *
 * Revision 1.1.2.1  2010-02-15 10:08:11  opolo
 * actualizados los nombres de los archivos y servicios
 *
 * Revision 1.1.4.3  2006/11/09 15:23:12  opolo
 * Use the new name of the classes that manage the pools
 * 	EDROOMPool EDROOMMemoryPool and EDROOMProtectedMemoryPool
 *
 * Revision 1.1.4.2  2006/10/18 18:31:51  opolo
 * Add Log
 *
 *
 * Revision 1.1.4.1  2006/10/18 18:07:20  opolo
 * *** empty log message ***
 * 
 */



#ifndef __EDROOM_TYPES_H
#define __EDROOM_TYPES_H

//******************************************************************************
//******************************************************************************
// EDROOMTYPES
//******************************************************************************
//******************************************************************************

/*!
 * \struct TEDROOMTransId
 * \brief struct that implements the transition identificator 
 * \author Oscar Rodriguez Polo
 */

struct TEDROOMTransId{
		
  		//!Local identifier in the context where the transition happens
		TEDROOMInt16 localId;
		
  		//!Distance to the context where the transition happens
		TEDROOMInt8	distanceToContext;
		
};


//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Component Types

class CEDROOMComponent;

class CEDROOMComponentMemory;


//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//  Timing Types

/*!
 * \enum EDROOMTimerState
 * \brief enum that defines the timer state  
 */
enum EDROOMTimerState{edroomTimerCancelled,edroomTimerReady, edroomTimerActive, 
	edroomTimerSent, edroomTimerDummy};  
	
class CEDROOMTimerInfo;

class CEDROOMTimingMemory;


//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//  Communication Types
#ifdef _EDROOM_IS_DEBUG_

extern const char * EDROOMErrorCommNames[];

extern CEDROOMstream EDROOMFError;
extern CEDROOMDummyStream EDROOMFDeb;
extern CEDROOMstream cout;


#endif

class CEDROOMConnection; 
class CEDROOMTXChannel;
class CEDROOMLocalTXChannel;
class CEDROOMLocalCommSAP;
//class CEDROOMRemoteTXChannel;
class CEDROOMRemoteRXChannel;
class CEDROOMRemoteCommSAP;

typedef int TEDROOMConnectionId;

enum TEDROOMMessageType {msgTypeSend, msgTypeInvoke, msgTypeReply};

//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//  Message Types

class CEDROOMMessage;
class CEDROOMSynchrMessage;
class CEDROOMTimeOutMessage;
class CEDROOMSynchrMessagesPool;

class CEDROOMMessagesPool;
class CEDROOMTimeOutMessagesPool;

typedef int TEDROOMSignal;

//const TEDROOMSignal EDROOMNoSignal=-1;

#define EDROOMNoSignal -1

//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//  Interface Types


class CEDROOMInterface;

/*!
 * \brief Typedef for connection identifier 
 */
typedef TEDROOMWord32 TEDROOMInterfaceID ;

/*!
 * \brief Typedef for component identifier
 */
typedef TEDROOMWord32 TEDROOMComponentID ;

// Remote Comm SAP

typedef TEDROOMWord32 (*pFunSerializeData)(const void * source, void * destination);
typedef TEDROOMWord32 (*pFunDeserializeData)(void * source, void * destination);

typedef TEDROOMWord32 (*pFunGetInformation)(TEDROOMSignal ,
		pFunDeserializeData * ppFunDeserializeData,
		CEDROOMProtectedMemoryPool **);

typedef TEDROOMUInt32 TEDROOMConnectionID;

class CEDROOMRemoteConnectionInfo;

typedef TEDROOMConnectionID (*pFunGetConnectionID)(CEDROOMRemoteConnectionInfo *);

//******************************************************************************
//******************************************************************************
// END EDROOMTYPES
//******************************************************************************
//******************************************************************************

#endif


/*!
 * \brief edroommessage header (edroom services library) 
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-03-04 09:08:17 $
 * \Version $Revision: 1.1.4.5 $
 *
 * $Log: edroommessage.h,v $
 * Revision 1.1.4.5  2010-03-04 09:08:17  opolo
 * Changed the names of the attributes
 *
 * Revision 1.1.4.4  2010-02-15 10:08:11  opolo
 * actualizados los nombres de los archivos y servicios
 *
 * Revision 1.1.4.3  2006/11/09 15:23:12  opolo
 * Use the new name of the classes that manage the pools
 * 	EDROOMPool EDROOMMemoryPool and EDROOMProtectedMemoryPool
 *
 * Revision 1.1.4.2  2006/10/18 18:31:51  opolo
 * Add Log
 *
 *
 * Revision 1.1.4.1  2006/10/18 18:07:20  opolo
 * *** empty log message ***
 * 
 */


#ifndef EDROOM_MESSAGE_H
#define EDROOM_MESSAGE_H




/*!
 * \class CEDROOMMessage
 * \brief class that implements the asynchronous messages. It is also the base 
 * class for any other type of messages
 * \author Oscar Rodriguez Polo
 */

class CEDROOMMessage
{

    //@{ Friend classes
	friend class CEDROOMComponent;
	friend class CEDROOMQueue;
	friend class CEDROOMInterface;
	friend class CEDROOMIRQInterface;
	friend class CEDROOMLocalTXChannel;
	friend class CEDROOMRemoteTXChannel;
	friend class CEDROOMRemoteRXChannel;
	friend class CMyCCMClientEDROOMServerSynchTXChannel;
	friend class CEDROOMSynchrMessage;
	friend class CEDROOMRemoteSynchrMessage;
	//@}


	//! Friend function that frees a message 
	friend void EDROOMFreeMessage(CEDROOMMessage *&);
	//! Friend function that frees the message back in a synchronous communication
	friend void EDROOMFreeMsgBack(CEDROOMMessage *&);

protected:


	/*!
    * \brief Virtual method that says if the message is cancelled or not
    * Only CEDROOMTimeOutMessage can be cancelled. 
    * \return always false  
    */

	TEDROOMBool virtual IsCancelled();

public:

	//!Pointer to the interface that receives the message
	CEDROOMInterface   * mp_Interface;    

	//Public attributes
//public:

  	//!Pointer to the Message Pool
	CEDROOMPool *mp_MsgPool;

  	//!Pointer to the Data Pool
	CEDROOMPool *mp_DataPool;

	//!Time when the message was sent
	Pr_Time   		Time;    			
	//!message signal
	TEDROOMSignal      signal;         
	//!message priority
	TEDROOMPriority    priority;      
	//!pointer to optional data
	void            *data;          
	//! Type of the message (msgTypeSend, msgTypeInvoke, msgTypeReply)
	TEDROOMMessageType type;

	TEDROOMWord32 GetMsgDataSize(void);

	/*!
    * \brief Access to the interface on wich message arrived
    * \return pointer to the interface 
    */
	CEDROOMInterface   * GetPInterface(); 

	/*!
    * \brief reply to the received Msg, it does not include an attached data 
    * \param signal of the reply message
    */
	virtual void reply(TEDROOMSignal signal);

	/*!
    * \brief reply to the received Msg, it does include an attached data 
    * \param signal signal of the reply message
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the data pool of pData 
    */
	virtual void reply(TEDROOMSignal signal
						,void * pData
						,CEDROOMPool *pDataPool);
						
	/*!
    * \brief reply to the received Msg where the signal and 
    * the attached data are the same of Msg
    * \param Msg Message that defines the signal and the attached data of the 
    * reply message
    */
	virtual void reply(CEDROOMMessage * Msg);
	
	/*!
    * \brief reply to the received Msg where the attached data is the same
    * of Msg but the signal is different 
    * \param Msg Message that defines the attached data of the reply message
    */

	virtual void reply(TEDROOMSignal, CEDROOMMessage * Msg);


	/*!
 	* \brief Constructor. Init mp_MsgPool and mp_DataPool to NULL
	*/

	CEDROOMMessage();

   /*!
 	* \brief Destructor, only to avoid warnings
	*/
	virtual ~CEDROOMMessage(){};


};



/*!
 * \class CEDROOMSynchrMessage
 * \brief class that implements the synchronous messages. 
 * \author Oscar Rodriguez Polo
 */


class CEDROOMSynchrMessage:public CEDROOMMessage
{
    //@{ Friend classes
	friend class CEDROOMInterface;
	friend class CEDROOMLocalTXChannel;
	friend class CEDROOMRemoteTXChannel;
	friend class CMyCCMClientEDROOMServerSynchTXChannel;
	//@}

protected:

	/** Semaphore used for the synchronization between the sender and the 
	*receiver
	*/
	Pr_SemaphoreBin         m_SynchrSem; 

	//!Pointer to the Msg Back
	CEDROOMMessage     *mp_MsgBack; 

	//!Is Sender is waiting?
	TEDROOMBool         m_IsSenderWaiting;    


public:

	/*!
    * \brief reply to the received Msg, it does not include an attached data 
    * \param signal of the reply message
    */
	void virtual reply(TEDROOMSignal signal);

	/*!
    * \brief reply to the received Msg, it does include an attached data 
    * \param signal signal of the reply message
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the data pool of pData 
    */
	void virtual reply(TEDROOMSignal signal
						,void * pData
						,CEDROOMPool *pDataPool);
						
	/*!
    * \brief reply to the received Msg where the signal and 
    * the attached data are the same of Msg
    * \param Msg Message that defines the signal and the attached data of the 
    * reply message
    */
	void virtual reply(CEDROOMMessage * Msg);
	
	/*!
    * \brief reply to the received Msg where the attached data is the same
    * of Msg but the signal is different 
    * \param Msg Message that defines the attached data of the reply message
    */

	void virtual reply(TEDROOMSignal, CEDROOMMessage * Msg);

	/*!
 	* \brief Constructor. Init PMsgPool and PDataPool to NULL
	*/

	CEDROOMSynchrMessage();
   
	/*!
 	* \brief Destructor, only to avoid warnings
	*/
	
	virtual ~CEDROOMSynchrMessage(){};

};

class CEDROOMRemoteSynchrMessage : public CEDROOMMessage
{

 friend class CEDROOMInterface;
 friend class CEDROOMRemoteTXChannel;

protected:

    CEDROOMMessage     *p_MsgBack; //apuntador al mensaje de retorno

public:

	/*!
    * \brief reply to the received Msg, it does not include an attached data
    * \param signal of the reply message
    */
    void virtual reply(TEDROOMSignal);

	/*!
    * \brief reply to the received Msg, it does include an attached data
    * \param signal signal of the reply message
    * \param pData pointer to the attached data
    * \param pDataPool pointer to the data pool of pData
    */
    void virtual reply(TEDROOMSignal
    		, void *,
    		CEDROOMPool *pDataPool);

	/*!
    * \brief reply to the received Msg where the signal and
    * the attached data are the same of Msg
    * \param Msg Message that defines the signal and the attached data of the
    * reply message
    */
    void virtual reply(CEDROOMMessage * Msg);

	/*!
    * \brief reply to the received Msg where the attached data is the same
    * of Msg but the signal is different
    * \param Msg Message that defines the attached data of the reply message
    */
    void virtual reply(TEDROOMSignal, CEDROOMMessage * Msg);

    // CONSTRUCTOR

    CEDROOMRemoteSynchrMessage();


    // DESTRUCTOR

    virtual ~CEDROOMRemoteSynchrMessage(){};

};



/*!
 * \class CEDROOMTimeOutMessage
 * \brief class that implements the timeout messages. 
 * \author Oscar Rodriguez Polo
 */

class CEDROOMTimeOutMessage:public CEDROOMMessage
{
	//@{ Friend classes
	friend class CEDROOMTimingSAP;
	friend class CEDROOMComponent;
	//@}


protected:

	/*!
    * \brief Virtual method that says if the message is cancelled or not
    * \return true if the message has been cancelled, false if not
    */

	TEDROOMBool virtual IsCancelled();

private:

  	//!Pointer to the Timer Info
	CEDROOMTimerInfo *mp_TimerInfo;         

  	//!Pointer to the Timer Info Pool 
	CEDROOMMemoryPool *mp_TimerInfoPool;

    //!Semaphore used for mutual exclusion
	Pr_SemaphoreRec *mp_Mutex;   


public:
	
	/*!
 	* Destructor, only to avoid warnings
	*/
	virtual ~CEDROOMTimeOutMessage(){};


};

/*!
 * \class CEDROOMMessagesPool
 * \brief class that implements the messages pool. 
 * \author Oscar Rodriguez Polo
 */

class CEDROOMMessagesPool : public CEDROOMMemoryPool {

public:
		
		
  	/*!
	* Set the memory of the pool 
   	* \param dimension defines the pool dimension
   	* \param pMessagePool pointer to the message pool
   	* \param pmemoryMarks pointer to the memory that stores the free marks
   	*/

	void SetMemory(TEDROOMUInt32 dimension
					, CEDROOMMessage * pMessagePool
  					, TEDROOMBool * pMemoryMarks);

	/*!
    * Allocation of a free CEDROOMMessage
    * \return a pointer to the CEDROOMMessage or NULL if none element 
    * 		  is available
    */
	CEDROOMMessage * AllocData();

	/*!
    * Destructor, only to avoid warnings
	*/
 	
	~CEDROOMMessagesPool(){};
};

/*!
 * \class CEDROOMTimeOutMessagesPool
 * \brief class that implements the timeout messages pool. 
 * \author Oscar Rodriguez Polo
 */

class CEDROOMTimeOutMessagesPool: public CEDROOMMemoryPool {

public:
		
  	/*!
	* Set the memory of the pool 
	* \param dimension defines the pool dimension
	* \param pTimeOutMessagePool pointer to the timeout message pool
	* \param memoryMarks pointer to the memory that stores the free marks
	*/

  	void SetMemory(TEDROOMUInt32 dimension
					, CEDROOMTimeOutMessage * pTimeOutMessagePool
  					, TEDROOMBool * pMemoryMarks);
  
	/*!
	* Allocation of a free CEDROOMTimeOutMessage
	* \return a pointer to the CEDROOMTimeOutMessage or NULL if none element 
	* 		  is available
	*/
	CEDROOMTimeOutMessage * AllocData();

	/*!
     * Destructor, only to avoid warnings
	*/

	~CEDROOMTimeOutMessagesPool(){};

};

/*!
 * \class CEDROOMSynchrMessageManager
 * \brief class that implements the synchronous messages pool. 
 * \author Oscar Rodriguez Polo
 */


class CEDROOMSynchrMessagesPool:public CEDROOMPool{

   //!Pointer to the unique synchronous message that the pool has
	CEDROOMSynchrMessage *  mp_SynchrMsg;

   //!Semaphore used for mutual exclusion access to the synchronous message
	Pr_SemaphoreBin        m_Mutex; 

public:

	TEDROOMUInt32 GetElementSize(void);

	/*!
 	* Constructor, inits the PSynchrMsg attribute with the pSynchrMsg parameter
    * \param pSynchrMsg pointer to the synchronous message 
	*/
	CEDROOMSynchrMessagesPool(CEDROOMSynchrMessage *  pSynchrMsg);

	/*!
    * Allocation of a free CEDROOMSynchrMessage, waiting until the message is 
    * available
    * \return a pointer to a free CEDROOMSynchrMessage 
    */

	CEDROOMSynchrMessage *  AllocData(void);


	/*!
    * Virtual method that marks the CEDROOMSynchrMessage as free
    * \param pData pointer to the CEDROOMSynchrMessage, it is not used  
    *
    * \return always 0  
    */
	
	TEDROOMInt8 FreeData(void * pData);

	/*!
 	* Destructor, only to avoid warnings
	*/
	~CEDROOMSynchrMessagesPool(){};

};

class CEDROOMRemoteSynchrMessagesPool:public CEDROOMPool{

   //!Pointer to the unique synchronous message that the pool has
	CEDROOMRemoteSynchrMessage *  mp_SynchrMsg;

   //!Semaphore used for mutual exclusion access to the synchronous message
	Pr_SemaphoreBin        m_Mutex;

public:

	TEDROOMUInt32 GetElementSize(void);

	/*!
 	* Constructor, inits the PSynchrMsg attribute with the pSynchrMsg parameter
    * \param pSynchrMsg pointer to the synchronous message
	*/
	CEDROOMRemoteSynchrMessagesPool(CEDROOMRemoteSynchrMessage *  pSynchrMsg);

	/*!
    * Allocation of a free CEDROOMSynchrMessage, waiting until the message is
    * available
    * \return a pointer to a free CEDROOMSynchrMessage
    */

	CEDROOMRemoteSynchrMessage *  AllocData(void);


	/*!
    * Virtual method that marks the CEDROOMSynchrMessage as free
    * \param pData pointer to the CEDROOMSynchrMessage, it is not used
    *
    * \return always 0
    */

	TEDROOMInt8 FreeData(void * pData);

	/*!
 	* Destructor, only to avoid warnings
	*/
	~CEDROOMRemoteSynchrMessagesPool(){};

};


#endif


/*!
 * \brief edroominterface header (edroom services library) 
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-03-04 09:08:17 $
 * \Version $Revision: 1.1.4.5 $
 * 
 * $Log: edroominterface.h,v $
 * Revision 1.1.4.5  2010-03-04 09:08:17  opolo
 * Changed the names of the attributes
 *
 * Revision 1.1.4.4  2010-02-15 10:08:11  opolo
 * actualizados los nombres de los archivos y servicios
 *
 * Revision 1.1.4.3  2006/11/09 15:23:12  opolo
 * Use the new name of the classes that manage the pools
 * 	EDROOMPool EDROOMMemoryPool and EDROOMProtectedMemoryPool
 *
 * Revision 1.1.4.2  2006/10/18 18:31:51  opolo
 * Add Log
 *
 *
 * Revision 1.1.4.1  2006/10/18 18:07:20  opolo
 * *** empty log message ***
 * 
 */
 



#ifndef __EDROOM_Interface
#define __EDROOM_Interface


#ifdef _EDROOM_IS_DEBUG_

/*!
 * \enum TEDROOMCommError
 * \brief enumerate to handle the communication errors 
 * \author Oscar Rodriguez Polo
 */

enum TEDROOMCommError  {EDROOMNoErrorComm, EDROOMEmptyPoolMens, 
						EDROOMSignalInvalidate, EDROOMFullQueueMens,
						EDROOMInterfaceDisconnected, EDROOMCommTimeOut, 
						EDROOMMsgBackUsed, EDROOMInterblock };

#endif


/*!
 * \class CEDROOMInterface
 * \brief class that implements the component interfaces.  
 * \author Oscar Rodriguez Polo
 */

class CEDROOMInterface{  
	
	//@{ Friend classes
	friend class CEDROOMLocalCommSAP;
	friend class CEDROOMRemoteCommSAP;
	friend class CEDROOMRegularRemoteCommSAP;
	friend class CEDROOMFragmentedRemoteCommSAP;
	friend class CEDROOMTimingSAP;
	friend class CEDROOMLocalTXChannel;
	friend class CEDROOMRemoteTXChannel;
	friend class CEDROOMRemoteRXChannel;
    friend class CEDROOMMyCCMCommSAP;

	friend class CEDROOMRemoteSynchrMessage;
	//@}
			 
protected:

	//!Pointer to the component that owns the interface
	CEDROOMComponent* mp_Component;

	//!Pointer to the channel connected to the interface
	CEDROOMTXChannel * mp_Channel;


#ifdef _EDROOM_IS_DEBUG_

	//!Is the interface registered ? 
	TEDROOMBool m_IsRegistered; 	
	//!Is the interface connected ? 
	TEDROOMBool m_IsConnected; 

#endif

	//!Interface Global identifier   
	TEDROOMInterfaceID m_IdInterface;


public:


#ifdef _EDROOM_IS_DEBUG_

	/*!
 	* Constructor. Init registered and connected to NULL
	*/
	CEDROOMInterface(); 

	/*!
    * send an asynchronous message with no attached data  
    * \param signal message identifier 
    * \param priority priority of the message
    * \return the communication error 
    */
	
	TEDROOMCommError	send (TEDROOMSignal signal, TEDROOMPriority priority); 

	/*!
    * send an asynchronous message with attached data 
    * \param signal message identifier 
    * \param priority priority of the message
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the attached data pool
    * \return the communication error 
    */
	TEDROOMCommError	send (TEDROOMSignal signal, TEDROOMPriority priority
								, void *pData, CEDROOMPool * pDataPool);
								
	TEDROOMCommError	send (CEDROOMMessage *message);  
	TEDROOMCommError	send (TEDROOMSignal signal,CEDROOMMessage *message);  
	TEDROOMCommError	send (TEDROOMSignal signal,TEDROOMPriority priority
							  ,CEDROOMMessage *message);  

#else

	/*!
    * send an asynchronous message with no attached data  
    * \param signal message identifier 
    * \param priority priority of the message
    */
	void	send (TEDROOMSignal signal, TEDROOMPriority priority); // Se da la prioridad

	/*!
    * send an asynchronous message with attached data 
    * \param signal message identifier 
    * \param priority priority of the message
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the attached data pool
    */
	void	send (TEDROOMSignal signal, TEDROOMPriority priority
								, void *pData, CEDROOMPool * pDataPool);
	
	void	send (CEDROOMMessage *message);  // reenvio de un mensaje
	void	send (TEDROOMSignal signal,CEDROOMMessage *message);  // reenvio de un mensaje
	void	send (TEDROOMSignal signal,TEDROOMPriority priority,CEDROOMMessage *message);  // reenvio de un mensaje

#endif

	// synchronous communication primitives:

	/*!
    * send an synchronous message with no attached data and wait the answer  
    * \param signal message identifier 
    * \param priority priority of the message
    * \return the reply message  
    */
	CEDROOMMessage *invoke(TEDROOMSignal signal,
						TEDROOMPriority priority=EDROOMprioURGENT);
						
	/*!
    * send an asynchronous message with attached data 
    * \param signal message identifier 
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the attached data pool
    * \return the reply message  
    */
	CEDROOMMessage *invoke(TEDROOMSignal signal, void *dataObjetPtr
												, CEDROOMPool * pDataPool);
												
	/*!
    * send an asynchronous message with attached data 
    * \param signal message identifier 
    * \param priority priority of the message
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the attached data pool
    * \return the reply message  
    */
	
	CEDROOMMessage *invoke(TEDROOMSignal signal,TEDROOMPriority priority, 
									void *pData, CEDROOMPool * apMemDats);


	CEDROOMMessage *invoke(CEDROOMMessage *message);  // reenvio de un mensaje
	CEDROOMMessage *invoke(TEDROOMSignal signal,CEDROOMMessage *message);  // reenvio de un mensaje
	CEDROOMMessage *invoke(TEDROOMSignal signal,TEDROOMPriority priority, CEDROOMMessage *message);  // reenvio de un mensaje


	/*!
    * operator == comparare with other CEDROOMInterface using idInterface  
    * \param edroominterface reference to the other interface 
    * \return true if match, false if not
    */
	TEDROOMBool operator ==(CEDROOMInterface &edroominterface);

	/*!
    * operator != comparare with other CEDROOMInterface using idInterface  
    * \param edroominterface reference to the other interface 
    * \return false if match, true if not
    */
	TEDROOMBool operator !=(CEDROOMInterface &edroominterface);

	/*!
    * applyConverFunct, convert the local signal identifier to the signal 
    * identifier of the destiny component 
    * \return the signal indentifier of the destiny component
    */
	TEDROOMSignal applyConverFunct(TEDROOMSignal signal);

	#ifdef _EDROOM_IS_DEBUG_

	//!name of the interface
	const char * EDROOMName;

	#endif


};

#ifdef _EDROOM_HANDLE_IRQS

/*!
 * \class CEDROOMIRQInterface
 * \brief class that implements the component interfaces with interrupt handlers  
 * \author Oscar Rodriguez Polo
 */

class CEDROOMIRQInterface: public CEDROOMInterface{

	//!IRQ Handler
	Pr_IRQHandler HandIRQ;
	
	//!Idle IRQ Handler
	Pr_IRQHandler HandIdle;
	
	//!End IRQ Look Semaphore 
	Pr_SemaphoreBin * EndIRQLook;
	
	//!IRQEvent Look 
	Pr_IRQEvent *IRQEventLook;
	
	//!priority of the message 
	TEDROOMPriority priority;
	
	//!IRQ number
	TEDROOMInt8 IRQ;
	
	//!Is IRQ Installed
	TEDROOMBool IRQInstalled;

public:

	/*!
    * Constructor 
    * \param irqHandler Interrupt Handler 
    * \param idleIrqHandler Idle Interrupt Handler
    * \param endIrqLook Semaphore for waiting the end of the irq service
    * \param priority Priority of the Message associated with the irq service
    * \param irqLevel Interrupt Level
    */
	
	CEDROOMIRQInterface(Pr_IRQHandler irqHandler, Pr_IRQHandler idleIrqHandler
							,Pr_IRQEvent &IRQEventLook 
							,Pr_SemaphoreBin & endIrqLook
							,TEDROOMPriority priority, TEDROOMInt8 irqLevel);

	/*!
    * New IRQ message is received  
    * \param signal message signal 
    * \param pData pointer to the data attached 
    * \param pDataPool pointer to the data pool
    */
	void	NewIRQMsg(TEDROOMSignal signal, void * pData=NULL
											, CEDROOMPool * pDataPool=NULL);

	/*!
    * Install IRQ handler   
    */
	
	void InstallHanler();

	/*!
    * Deinstall IRQ handler (install the dummy handler)   
    */
	void DeInstallHanler();

	/*!
    * End IRQ Handler Task   
    */
	void EndIRQHandlerTask();

};

#endif



#endif


/*!
 * \brief edroomtiming header (edroom services library) 
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-03-04 09:08:17 $
 * \Version $Revision: 1.1.4.5 $
 *
 * $Log: edroomtiming.h,v $
 * Revision 1.1.4.5  2010-03-04 09:08:17  opolo
 * Changed the names of the attributes
 *
 * Revision 1.1.4.4  2010-02-15 10:08:11  opolo
 * actualizados los nombres de los archivos y servicios
 *
 * Revision 1.1.4.3  2006/11/09 15:20:16  opolo
 * Define the EDROOMTimingInterface class
 * Use the new name of the classes that manage the pools
 * 	CEDROOMPool EDROOMMemoryPool and EDROOMProtectedMemoryPool
 *
 * Revision 1.1.4.2  2006/10/18 18:31:51  opolo
 * Add Log
 *
 *
 * Revision 1.1.4.1  2006/10/18 18:07:20  opolo
 * *** empty log message ***
 * 
 */


#ifndef __EDROOM_TIMING_SERVICE_H
#define __EDROOM_TIMING_SERVICE_H

class   CEDROOMTimingSAP;

//***************************************************************************

//! Define the Stack of the Timing Task
#define _EDROOM_TIMING_TASK_STACK       1024  

//***************************************************************************


//***************************************************************************
/*!
*  \class CEDROOMTimerInfo
*  \brief Contains the information about an EDROOMTimer.
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************

class CEDROOMTimerInfo{

//@{ Friend classes

friend class   CEDROOMTimingSAP;
friend class   CEDROOMTimeOutMessage;
//@}


private:

	//! Index used to identify the Timer 
	TEDROOMUInt32 m_Index; 
	
	//! TimeStamp when the Timer was programmed, It is also used to identify it 
	Pr_Time m_TimeStamp;  

	//! Time when the Timeout Message will be sent to the component 
	Pr_Time m_Time;  

	//! Pointer to the next CEDROOMTimerInfo
	/*
	 * It is used to build a list of CEDROOMTimerInfo
	 */
	CEDROOMTimerInfo *mp_Next;

	//! Timer State 
	EDROOMTimerState m_State;

	//! Pointer to the Timeout Message 
	CEDROOMTimeOutMessage *mp_Msg;


};

//***************************************************************************
/*!
*  \class CEDROOMTimerInfoPool
*  \brief Manages as a Pool the memory of EDROOMTimerInf elements.
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************

class CEDROOMTimerInfoPool: public CEDROOMMemoryPool {


public:
	 
  	 /*!
   	 * \brief Set the memory of the pool 
   	 * \param dimension defines the pool dimension
   	 * \param pTimerInfoPool pointer to the CEDROOMTimerInfo memory pool
   	 * \param pMarksMemory pointer to the memory that stores the free marks
   	 */
	 		
	void SetMemory(TEDROOMUInt32 dimension, CEDROOMTimerInfo* pTimerInfoPool
	 				,TEDROOMBool * pMarksMemory );
   
    /*!
   	* \brief Allocation of a free CEDROOMTimerInfo 
    * \param rElemIndex reference to the index of the element, modified by this
    * 				  method
    * \return a pointer to the element or NULL if none element is available
    */
	CEDROOMTimerInfo * AllocData(TEDROOMUInt32& rElemIndex);

};


//***************************************************************************
/*!
*  \class CEDROOMTimer
*  \brief The application code can use it to cancel the programmed timers.
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************


class CEDROOMTimer{

friend class   CEDROOMTimingSAP;

	//! Index used to identify the Timer 
	TEDROOMUInt32 m_Index; 

	//! TimeStamp when the Timer was programmed, It is also used to identify it 
	Pr_Time m_TimeStamp;  

	//! Pointer to the Timer Information
	CEDROOMTimerInfo * mp_TimerInfo; 


public:

	/*!
   	* \brief Constructor
    */
	CEDROOMTimer();

					
	/*!
   	* \brief Check if the Timer is valid
    * \return true if it is valid, false if it is not
    */

	TEDROOMBool IsValid();


};

//***************************************************************************
/*!
*  \class CEDROOMTimerConfig
*  \brief It is used to send the timer information to the Timing Task
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************


class CEDROOMTimerConfig {

friend class   CEDROOMTimingSAP;

		//! Time when the Timeout Message will be sent to the component 
		Pr_Time m_Time;

		//! Pointer to the Timer Information
		CEDROOMTimerInfo * mp_TimerInfo;

};

//***************************************************************************
/*!
*  \class CEDROOMTimingInterface
*  \brief Used to define the Timing Ports
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************



class CEDROOMTimingInterface:public CEDROOMInterface{

friend class CEDROOMComponent;

private:

   //! Pointer to the Timing SAP
   CEDROOMTimingSAP * mp_TimingSAP;

   //! Maximun Number of Timers 
   TEDROOMUInt32 m_MaxNumTimers;

   //! Free Timers 
   TEDROOMUInt32 m_FreeTimers;

#ifdef __EDROOMSL_2010
   //! TimeOut of the last programmed timer 
   Pr_Time m_LastTimeout;

   //! Minimal Period 
   Pr_Time m_MinPeriod;
   
#endif   
   	
public:

    /*!
   	* \brief Constructor
    * \param pTimingSAP pointer to the Timing SAP
    * \param maxNumTimers maximun number of Timers 
    * \param minPeriod of the programmed timers with this timing interface
    */

#ifdef __EDROOMSL_2010

	CEDROOMTimingInterface( CEDROOMTimingSAP * pTimingSAP
													,TEDROOMUInt32 maxNumTimers
													,Pr_Time minPeriod);
#else


	CEDROOMTimingInterface( CEDROOMTimingSAP * pTimingSAP
												,TEDROOMUInt32 maxNumTimers);

#endif

    /*!
   	* \brief Method for programming a Timer using absolute time
    * \param timeValue is the absolute time reference of the timer 
    * \param msgPrio is the priority of the TimeOut message that will be sent 
    * 		when the time reference will be reach
    * \return an CEDROOMTimer object that can be used to check if the timer has
    * been properly programmed or to cancel the timer
    */


	CEDROOMTimer InformAt(Pr_Time timeValue,TEDROOMPriority msgPrio);

    /*!
   	* \brief Method for programming a Timer using an absolute time with a data 
   	* attached 
    * \param timeValue is the absolute time reference of the timer 
    * \param msgPrio is the priority of the TimeOut message that will be sent 
    * 		when the time reference will be reach
    * \param pData pointer to the data
    * \param pData pointer to the pool from the data comes
    * \return an CEDROOMTimer object that can be used to check if the timer has
    * 		been properly programmed or to cancel the timer
    */

	CEDROOMTimer InformAt(Pr_Time timeValue,TEDROOMPriority msgPrio,void *pData,
												CEDROOMPool * pDataPool);

   /*!
   	* \brief Method for programming a Timer using relative time
    * \param interval is the relative time reference of the timer 
    * \param msgPrio is the priority of the TimeOut message that will be sent 
    * 		when the time reference will be reach
    * \return an CEDROOMTimer object that can be used to check if the timer has
    * been properly programmed or to cancel the timer
    */


	CEDROOMTimer InformIn  (Pr_Time interval,TEDROOMPriority msgPrio);


    /*!
   	* \brief Method for programming a Timer using relative time with a data 
   	* attached 
    * \param interval is the relative time reference of the timer 
    * \param msgPrio is the priority of the TimeOut message that will be sent 
    * 		when the time reference will be reach
    * \param pData pointer to the data
    * \param pData pointer to the pool from the data comes
    * \return an CEDROOMTimer object that can be used to check if the timer has
    * 		been properly programmed or to cancel the timer
    */

	CEDROOMTimer InformIn(Pr_Time interval,TEDROOMPriority msgPrio,void *pData,
												CEDROOMPool * pDataPool);

    /*!
   	* \brief Method for outstanding timers:
    * \param rTimerId reference to the Timer Identification 
	*/
	void  cancelTimer(CEDROOMTimer &rTimerId);

	/*!
   	* \brief Method for get Current Time:
    * \param time reference to the Timer Identification 
	*/
	
	void currentTime(Pr_Time &time);

	/*!
   	* \brief Method for get Current Time:
    * \param time reference to the Timer Identification 
	*/
	Pr_Time currentTime();

};

//***************************************************************************
/*!
*  \class CEDROOMTimingSAP
*  \brief Class that implements the Timing Service Access Point.
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************


class CEDROOMTimingSAP{


	friend class CEDROOMTimingInterface;

private:

	//! Pointer to the component owner of the Timing SAP
	CEDROOMComponent * mp_Component;   


	//! Resource Semaphore for the mutual exclusion access of the Timing SAP
	Pr_SemaphoreRec m_Mutex;   
								
	//! Semaphore for synchronization 
	Pr_SemaphoreBin m_SynchrSem;

	//! Memory Pool for dynamic allocation of the timers information
	CEDROOMTimerInfoPool *mp_TimerInfoPool;

	//! Pointer to the next TimerInfo when the TimerInfo is in a List 
	CEDROOMTimerInfo *mp_NextTimer;

	//! Memory Pool for dynamic allocation of the TimeOut Messages
	CEDROOMTimeOutMessagesPool *mp_TimeOutMsgPool;

	//! Pointer to timer task object 
	Pr_Task *mp_TimerTask;

	//! Timer task object 
	Pr_Task m_TimerTask;

	//! Semaphore for waiting Component 
	Pr_SemaphoreBin m_WaitComponentSem;

#ifdef _EDROOM_SYSTEM_CLOSE

	//! Set true when SAP is finished 
	bool m_IsSAPFinished;

#endif

public:


    /*!
   	* \brief Constructor
    * \param pComponent pointer to Component that  
    * \param maxNumTimers Maximun number of Timers 
    * \param pTimmingMemory pointer to Memory of the TimingSAP 
    */
	CEDROOMTimingSAP(CEDROOMComponent * pComponent,unsigned int maxNumTimers, 
										CEDROOMTimingMemory *pTimmingMemory);

	

#ifdef _EDROOM_SYSTEM_CLOSE

	/*!
   	* \brief Destructor, only if system must close
    */
	~CEDROOMTimingSAP();

#endif


	/*!
   	* \brief Method for programming a Timer using an absolute time with a data 
   	* attached 
    * \param interface is the interface that requires the timing service
    * \param timeValue is the absolute time reference of the timer 
    * \param msgPrio is the priority of the TimeOut message that will be sent 
    * 		when the time reference will be reach
    * \return an CEDROOMTimer object that can be used to check if the timer has
    * 		been properly programmed or to cancel the timer
    */
	CEDROOMTimer InformAt(CEDROOMTimingInterface* interface, Pr_Time timeValue
												,TEDROOMPriority MsgPrio
												, void *data
												,CEDROOMPool * bloqueMemData);


	/*!
   	* \brief Method for canceling outstanding timers:
    * \param interface is the interface that requires the timing service
    * \param rTimerId reference to the Timer Identification 
	*/

	void  cancelTimer(CEDROOMTimingInterface* interface, CEDROOMTimer &timerId);

	/*!
   	* Code that implements the task associated to Timing SAP
    */
	
#ifdef _EDROOM_TASK_POSIX_

    	static void * EDROOMfunTimer(void * paramDumy);

#else
    	static Pr_TaskRV_t EDROOMfunTimer(Pr_TaskP_t);
#endif
	
	
	
	

	/*!
   	* Method for starting the Timing Service 
	*/

	void  Start();


};

//***************************************************************************
/*!
*  \class CEDROOMTimingMemory
*  \brief Class that implements the Timing Service Memory.
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************


class CEDROOMTimingMemory{

friend class CEDROOMTimingSAP;

	public:

	/*!
   	* Memory of the timer information 
	*/
	  CEDROOMTimerInfoPool  m_TimerInfoMem;

	/*!
   	* Memory of the timeout messages 
	*/
	  CEDROOMTimeOutMessagesPool  m_TimeOutMessMem;
						 
	/*!
   * Set the memory of the timing service
   * \param elemNumber defines the number of elements of timing service
   * \param pTimerInfoMem pointer to the data memory pool of the timing 
   * 							information elements 
   * \param pTimerInfoMemMarks pointer to the memory that stores the free marks 
   * 							of the timing information elements
   * \param pTimeOutMessageMem pointer to the data memory pool of the timeout
   * 							messages
   * \param pTimeOutMessageMemMarks pointer to the memory that stores the free 
   * 							marks of the timeout messages
   */
	
	  void SetMemory(TEDROOMUInt32  elemNumber, CEDROOMTimerInfo * pTimerInfoMem
	  				, TEDROOMBool * pTimerInfoMemMarks
	  				, CEDROOMTimeOutMessage* pTimeOutMessageMem
	  				, TEDROOMBool *pTimeOutMessageMemMarks);

};



#endif


/*!
 * \brief edroomqueue header (edroom services library) 
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-03-04 09:08:17 $
 * \Version $Revision: 1.1.4.5 $
 * 
 * $Log: edroomqueue.h,v $
 * Revision 1.1.4.5  2010-03-04 09:08:17  opolo
 * Changed the names of the attributes
 *
 * Revision 1.1.4.4  2010-02-15 10:08:11  opolo
 * actualizados los nombres de los archivos y servicios
 *
 * Revision 1.1.4.3  2006/11/09 15:23:12  opolo
 * Use the new name of the classes that manage the pools
 * 	EDROOMPool EDROOMMemoryPool and EDROOMProtectedMemoryPool
 *
 * Revision 1.1.4.2  2006/10/18 18:31:51  opolo
 * Add Log
 *
 *
 * Revision 1.1.4.1  2006/10/18 18:07:20  opolo
 * *** empty log message ***
 *
 */



#ifndef __EDROOM_QUEUE_H
#define __EDROOM_QUEUE_H

//***************************************************************************
/*!
*  \class CEDROOMQueue
*  \brief It implements the message queues of the components
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************


class CEDROOMQueue
{

public:

//***************************************************************************
/*!
*  \class CQueueNode
*  \brief It implements a queue node 
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************

  class CQueueNode{               
	friend class CEDROOMQueue;

	//! Pointer to the message 
	CEDROOMMessage * mp_Msg;
	//! Pointer to the message next node
	CQueueNode *mp_Next;

	public:

	/*!
   	* \brief Constructor
    */
	CQueueNode();

  };


//***************************************************************************
/*!
*  \class CEDROOMQueueNodesPool
*  \brief it handles the memory of the queue 
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************


   class CEDROOMQueueNodesPool: public CEDROOMMemoryPool {

	friend class CEDROOMComponentMemory;

	   public:
	
		/*!
	   * \brief Set the memory of the timing service
	   * \param elemNumber defines the number of elements of the queue
	   * \param pPoolData pointer to the data memory of the queue
	   * \param pPoolMarks pointer to the memory that stores the free marks 
	   * 							of the queue elements
	   */
	
		void SetMemory(TEDROOMUInt32 elemNumber, CQueueNode * pPoolData
													,TEDROOMBool * pPoolMarks);

 	 
 	 	/*!
	   * \brief Alloc Data from the pool
	   * \return a node from the pool 
	   */
		CQueueNode * AllocData();

  };


//***************************************************************************
/*!
*  \class CQueueHead
*  \brief it implements the head of the queue 
*  \author Oscar Rodriguez Polo
*/
//***************************************************************************

  class CQueueHead{            

	friend class CEDROOMQueue;

	//!Priority of the queue												
	TEDROOMPriority m_Priority;
	//!Pointer to the first element 												
	CQueueNode *mp_First;
	//!Pointer to the last element 												
	CQueueNode *mp_Last;
	//!Pointer to the head of the next queue												
	CQueueHead *mp_Next;
	
	public:
	/*!
   	* \brief Constructor
    */
	
	CQueueHead();
  };

public:


#ifdef _EDROOM_IS_DEBUG_

 /*!
  * \brief Constructor
  * \param maxNumMsg Maximum number of Messages
  * \param pComponent pointer to the Component
  * \param prioNumber number of diferent priorities
  * \param pComponentMemory  pointer to component memory that includes the
  * 							queue nodes memory
  * \param pQueueName name of the queue
  */

  CEDROOMQueue(unsigned Max_Num_Mess,
  					Pr_Task * pTask,
  					Pr_SemaphoreRec * pMutexSem,
  					unsigned prioNumber,
  					CEDROOMQueueNodesPool * pNodesPool,
  					CQueueHead * pQueueHeads,
  					const char * pQueueName );


#else

  	/*!
   	* \brief Constructor
    * \param maxNumMsg Maximum number of Messages
    * \param pComponent pointer to the Component
    * \param prioNumber number of diferent priorities 
    * \param pComponentMemory  pointer to component memory that includes the 
    * 							queue nodes memory
    */


	CEDROOMQueue(unsigned Max_Num_Mess,
						Pr_Task * pTask,
						Pr_SemaphoreRec * pMutexSem,
						unsigned prioNumber,
						CEDROOMQueueNodesPool * pNodesPool,
						CQueueHead * pQueueHeads);

#endif

#ifdef _EDROOM_SYSTEM_CLOSE

  	/*!
   	* \brief Destructor
    */

	~CEDROOMQueue();


  	/*!
   	* \brief Free queue memory
    */
	void FreeMem();


#endif

	/*!
   	* \brief Check if the queue is full
   	* \return true if queue is full
    */
	
	TEDROOMBool IsFull();

#ifdef _EDROOM_IS_DEBUG_

	/*!
   	* \brief Put a message in the queue, keeping it sorted by message priority  
    * \param pMsg message pointer 
    * \return 0 if there is no error
    */
	
	TEDROOMInt8 In (CEDROOMMessage* pMsg);  
	
	
#else


	/*!
   	* \brief Put a message in the queue, keeping it sorted by message priority  
    * \param pMsg message pointer 
    */
	
	void In (CEDROOMMessage* p_Msg);  

#endif

#ifdef _EDROOM_IS_DEBUG_

	/*!
   	* \brief Take a message from the queue  
    * \param rpMsg reference to the message pointer 
    * \return 0 if there is no error
    */

	TEDROOMInt8 Out(CEDROOMMessage * & rpMsg);      


#else

	/*!
   	* \brief Take a message from the queue  
    * \param rpMsg reference to the message pointer 
    * \return true everything is OK
    */
		
	TEDROOMBool Out(CEDROOMMessage * & rpMsg);      


#endif
	
	/*!
   	* \brief Set component task priority to the most priorized message of the queue
    */

	void SetToMsgPriority(void);

	/*!
	 * \brief Gets the priority of the non-empty highest priority queue.
	 */
	TEDROOMPriority GetMaxQueuedMsgPriority(void);


protected:

// ****************************************************************************
//		Protected attributes
// ****************************************************************************

	//! Pointer to the Task owner of the queue
	Pr_Task        *mp_Task;

	Pr_SemaphoreRec * mp_MutexSem;

	//! number of different priorities 
	unsigned m_PrioNumber;       

	//! maximum number of messages   
	unsigned m_MaxNumMsg;   
			

	//! Queue messages counter 
	unsigned m_MsgCounter;       


	/*! New Message semaphore. Out method waits for this semaphore when queue is 
	*   empty
	*/
	Pr_SemaphoreBin 		m_NewMsgSem; 


	//! Component Task is blocked 
	
	TEDROOMBool m_IsBlocked;               

	//! Queue Heads. The queue is in facts an array of queues, one per priority
	CQueueHead  * mp_QueueHeads;

	/*! pointer to the first queue head that contains highest priority messages
	*   and is the first node of a list of queue heads sorted by priority
	*/ 
	CQueueHead  * mp_FirstQueueHead;

	  
	//! pointer to the queue nodes memory pool 
	CEDROOMQueueNodesPool   *mp_NodesPool;

#ifdef _EDROOM_IS_DEBUG_

	const char * mp_QueueName;

#endif


// ****************************************************************************
//		Protected methods
// ****************************************************************************

	/*!
   	* \brief Update the sorted (by priority) list of queue heads
   	* \param newMsgPriority is the priority of the new message added that
   	* 		 				causes the updating  
    */
	
	void UpDateSortedQueueHeadsList(TEDROOMPriority newMsgPriority);


	/*!
   	* \brief Put a node in the queue 
   	* \param queueHead is the queue head where the node is added 
   	* \param node is the node that is going to be added
   	* \return true if the queue head was empty  
    */
	
	TEDROOMBool PutInNode(CQueueHead *queueHead , CQueueNode * node);

	/*!
   	* \brief Take out a node from the highest priority queue 
   	* \param rpNode is a reference to the pointer that is taken    
   	* \param rPriority is a reference to priority of the highest priority queue  
   	*/

	void TakeOutNode(CQueueNode * &rpNode, TEDROOMPriority &rPriority); 


};




#endif



/*!
 * \brief edroomcomm header (edroom services library) 
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-03-04 09:08:17 $
 * \Version $Revision: 1.1.4.5 $
 * 
 * $Log: edroomcomm.h,v $
 * Revision 1.1.4.5  2010-03-04 09:08:17  opolo
 * Changed the names of the attributes
 *
 * Revision 1.1.4.4  2010-02-15 10:08:11  opolo
 * actualizados los nombres de los archivos y servicios
 *
 */
 


#ifndef __EDROOM_CSAP_H
#define __EDROOM_CSAP_H

//******************************************************************************
/*!
 * \class CEDROOMLocalTXChannel
 * \brief This is the base class for TX EDROOM connection channels
 *
 * \author Oscar Rodriguez Polo
 */
//******************************************************************************

class CEDROOMTXChannel{

friend class CEDROOMLocalCommSAP;
friend class CEDROOMRemoteCommSAP;

friend class CEDROOMInterface;
friend class CEDROOMConnection;

protected:

	//! pointer to the sender to receiver signal translator
	TEDROOMSignal  (*mp_SenderToReceiverSignalTranslator) (TEDROOMSignal );

public:
	void SetSenderToReceiveSignalTranslator(TEDROOMSignal (senderToNetworkTranslator) (TEDROOMSignal))
	{
		mp_SenderToReceiverSignalTranslator = senderToNetworkTranslator;
	}
	/** Constructor, it inits NULL all the attributes 
	 */
	CEDROOMTXChannel(){}
	
	/** Destructor
	 */
	virtual ~CEDROOMTXChannel(){}
	
	/*!
    * \brief send an asynchronous message 
    * \param signal message identifier 
    * \param priority priority of the message
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the attached data pool
    */
	virtual void send (TEDROOMSignal signal, TEDROOMPriority priority, void *pData
								, CEDROOMPool * pDataPool)=0;

	/*!
    * \brief send an asynchronous message 
    * \param signal message identifier 
    * \param priority priority of the message
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the attached data pool
    * \return the reply message  
    */
	virtual CEDROOMMessage *invoke(TEDROOMSignal signal, TEDROOMPriority priority
								, void *pData, CEDROOMPool * pDataPool)=0;


};


//******************************************************************************
/*!
 * \class CEDROOMLocalTXChannel
 * \brief This class implements the EDROOM connection channels
 *
 * \author Oscar Rodriguez Polo
 */
//******************************************************************************

class CEDROOMLocalTXChannel: public CEDROOMTXChannel{

friend class CEDROOMLocalCommSAP;
friend class CEDROOMInterface;
friend class CEDROOMLocalConnection;

protected:

	//! pointer to Sender Port
	CEDROOMInterface * mp_SenderPort;    
	//! pointer to Receiver Port 
	CEDROOMInterface * mp_ReceiverPort;


	//! pointer to Sender Task 
	Pr_Task  *mp_SenderTask;
	//! pointer to Receiver Task 
   	Pr_Task  *mp_ReceiverTask;

	//! pointer to Receiver Queue  
   	CEDROOMQueue *mp_ReceiverQueue;


	//! pointer to Receiver Message Pool  
	CEDROOMMessagesPool *mp_ReceiverMsgPool;

	//! pointer to Message Back pointer 
	//!todo ver si hay que eliminar 
	CEDROOMMessage ** mpp_MsgBack;
	
	//! pointer to Message Back 
	CEDROOMMessage * mp_MessageBack;
	
	//! pointer to Synchronous Messages Pool
	CEDROOMSynchrMessagesPool *mp_SynchrMsgPool;


public:

	/** Constructor, it inits NULL all the attributes 
	 */
	CEDROOMLocalTXChannel();
	
	/** Destructor, it inits NULL all the attributes 
	 */
	virtual ~CEDROOMLocalTXChannel(){};

	/*!
    * \brief send an asynchronous message 
    * \param signal message identifier 
    * \param priority priority of the message
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the attached data pool
    */
	void send (TEDROOMSignal signal, TEDROOMPriority priority, void *pData
								, CEDROOMPool * pDataPool);

	/*!
    * \brief send an asynchronous message 
    * \param signal message identifier 
    * \param priority priority of the message
    * \param pData pointer to the attached data 
    * \param pDataPool pointer to the attached data pool
    * \return the reply message  
    */
	CEDROOMMessage *invoke(TEDROOMSignal signal, TEDROOMPriority priority
								, void *pData, CEDROOMPool * pDataPool);


};

//******************************************************************************
/*!
 * \class CEDROOMLocalConnection
 * \brief This class implements the EDROOM local connection 
 *
 * \author Oscar Rodriguez Polo
 */
//******************************************************************************

class CEDROOMLocalConnection{

friend class CEDROOMLocalCommSAP;

	//! connection channel 1
	CEDROOMLocalTXChannel m_Channel1;
	//! connection channel 2
	CEDROOMLocalTXChannel m_Channel2;

		
};


//******************************************************************************
/*!
 * \class CEDROOMLocalCommSAP
 * \brief This class implements the EDROOM local communication service access 
 * point
 *
 * \author Oscar Rodriguez Polo
 */
//******************************************************************************

class CEDROOMLocalCommSAP{


public:

#ifdef _EDROOM_IS_DEBUG_

	/*!
    * \brief register the Interface 
    * \param id interface local identifier
    * \param interface reference to the interface
    * \param pComponent pointer to the component
    * \param interfaceName interfaceName
    * \return value!=0 if there is an error 
    */
	TEDROOMInt32 RegisterInterface(TEDROOMInterfaceID id
						, CEDROOMInterface & interface
						, CEDROOMComponent* pComponent
						, const char * interfaceName
						);

#else

	/*!
    * \brief register the Interface 
    * \param id interface local identifier
    * \param interface reference to the interface
    * \param pComponent pointer to the component
    * \return a value !=0 if there is an error 
    */
	TEDROOMInt32 RegisterInterface( TEDROOMInterfaceID id
						, CEDROOMInterface & interface
						, CEDROOMComponent* pComponent);

#endif
	
	/*!
    * \brief Connect the components interfaces 
    * \param interfaceComp1 reference to component 1 interface 
    * \param interfaceComp2 reference to component 2 interface 
    * \param connection reference to the object that handles the connection
    * \param comp1ToComp2SignalTranslator component1 to component2 signal 
    * 			translator
    * \param comp2ToComp1SignalTranslator component2 to component1 signal 
    * 			translator
    */
	void Connect(CEDROOMInterface & interfaceComp1
				,CEDROOMInterface & interfaceComp2
				,CEDROOMLocalConnection &connection 
				,TEDROOMSignal  (comp1ToComp2SignalTranslator) (TEDROOMSignal)
				,TEDROOMSignal  (comp2ToComp1SignalTranslator) (TEDROOMSignal));
	

#ifdef _EDROOM_SYSTEM_CLOSE

	/*!
    * \brief Deregister a components interface
    * \param interface reference to component interface 
    * \return a value !=0 if there is an error 
    */
	TEDROOMInt32 DeregisterInterface(CEDROOMInterface & interface);


#endif


};

#endif


#ifndef EDROOMREMOTECOMM_H_
#define EDROOMREMOTECOMM_H_


class CEDROOMRemoteConnectionInfo {

};

class CEDROOMRemoteCommSAP;
class CEDROOMRemoteConnection;

class CEDROOMRemoteTXChannel: public CEDROOMTXChannel{

friend class CEDROOMRemoteCommSAP;
friend class CEDROOMInterface;
friend class CEDROOMRemoteConnection;
friend class CEDROOMRemoteRXChannel;

protected:

	//! pointer to Sender Port
	CEDROOMInterface * mp_SenderPort;

	//! pointer to Sender Component
	CEDROOMComponent * mp_SenderComponent;

	Pr_SemaphoreBin m_InvokeSem;

	//! pointer to Sender Task
	Pr_Task  *mp_SenderTask;

	//! pointer to Message Back
	CEDROOMMessage * mp_MessageBack;

	//! Synchronous Message for the component TO SEND
	CEDROOMSynchrMessage m_SynchrMsg;

    //! Comm SAP attatched to this RemoteTXChannel
    CEDROOMRemoteCommSAP * mp_CommSAP;

	//! pointer to Comm SAP Message Pool
	CEDROOMMessagesPool *mp_CommSAPMsgPool;

    //! Sender Global Interface ID
    TEDROOMInterfaceID m_senderInterfaceID;

    TEDROOMComponentID m_senderGlobalComponentID;

    //! Destination Interface ID
    TEDROOMInterfaceID m_destinationInterfaceID;

    TEDROOMComponentID m_destinationGlobalComponentID;

    CEDROOMRemoteConnectionInfo * mp_ConnectionInfo;

    pFunSerializeData (*pGetSerializeFun) (TEDROOMSignal);

    CEDROOMRemoteConnection * mp_Connection;


public:

    TEDROOMInterfaceID GetSenderInterfaceID(void)
    {
    	return m_senderInterfaceID;
    }

    TEDROOMComponentID GetSenderComponentID(void)
    {
    	return m_senderGlobalComponentID;
    }

    TEDROOMInterfaceID GetDestinationInterfaceID(void)
    {
    	return m_destinationInterfaceID;
    }

    TEDROOMComponentID GetDestinationComponentID(void)
    {
    	return m_destinationGlobalComponentID;
    }

    pFunSerializeData GetSerializeFunction(TEDROOMSignal signal)
    {
    	return pGetSerializeFun(signal);
    }

    CEDROOMRemoteConnectionInfo * GetConnectionInfo(void)
    {
    	return mp_ConnectionInfo;
    }

	/** Constructor, it inits NULL all the attributes
	 */
	CEDROOMRemoteTXChannel();

	/** Destructor, it inits NULL all the attributes
	 */
	virtual ~CEDROOMRemoteTXChannel(){};

	/*!
    * \brief send an asynchronous message
    * \param signal message identifier
    * \param priority priority of the message
    * \param pData pointer to the attached data
    * \param pDataPool pointer to the attached data pool
    */
	void send (TEDROOMSignal signal, TEDROOMPriority priority, void *pData
								, CEDROOMPool * pDataPool);

	/*!
    * \brief send an asynchronous message
    * \param signal message identifier
    * \param priority priority of the message
    * \param pData pointer to the attached data
    * \param pDataPool pointer to the attached data pool
    * \return the reply message
    */
	CEDROOMMessage *invoke(TEDROOMSignal signal, TEDROOMPriority priority
								, void *pData, CEDROOMPool * pDataPool);

	/*!
    * \brief reply a synchronous message
    * \param signal message identifier
    * \param priority priority of the message
    * \param pData pointer to the attached data
    * \param pDataPool pointer to the attached data pool
    */
	void reply (TEDROOMSignal signal, TEDROOMPriority priority, void *pData
			  , CEDROOMPool * pDataPool);

};

class CEDROOMRemoteRXChannel {

	friend class CEDROOMRemoteCommSAP;
	friend class CEDROOMRemoteConnection;
	friend class CEDROOMRemoteTXChannel;

protected:

	//! pointer to Receiver Port
	CEDROOMInterface * mp_ReceiverPort;

	//! pointer to Sender Task
	Pr_Task  *mp_ReceiverTask;

    pFunGetInformation mp_funGetInformation;

	//! pointer to the sender to receiver signal translator
	TEDROOMSignal  (*mp_NetworkToReceiverSignalTranslator) (TEDROOMSignal );

	//! pointer to Receiver Queue
   	CEDROOMQueue *mp_ReceiverQueue;

	//! pointer to Receiver Asynchronous Message Pool
	CEDROOMMessagesPool *mp_ReceiverMsgPool;

	//! pointer to Message Back
	CEDROOMMessage * mp_MessageBack;

	//! Synchronous message for the component TO RECEIVE
	// There is only one needed, because it can only receive
	// one synchronous message per interface..
	CEDROOMRemoteSynchrMessage m_remoteSynchrMsg;

	CEDROOMRemoteSynchrMessagesPool mp_RemoteSynchrMsgPool;

    CEDROOMRemoteConnection * mp_Connection;

public:

	/** Constructor, it inits NULL all the attributes
	 */
   	CEDROOMRemoteRXChannel();

    /* This function checks the data received, deserializes the data if
     * necessary and unlocks the mutex if it is a reply message */
    TEDROOMWord32 ComponentReceive (TEDROOMSignal signal,
                          TEDROOMMessageType msgType,
                          TEDROOMPriority priority,
                          void * data,
                          TEDROOMWord32 dataSize);

};

class CEDROOMRemoteConnection{

friend class CEDROOMRemoteCommSAP;

public:

	//! connection channel 1
	CEDROOMRemoteTXChannel m_TXChannel;
	//! connection channel 2
	CEDROOMRemoteRXChannel m_RXChannel;


};

class CEDROOMRemoteConnectionLocator;

class CEDROOMRemoteConnectionLocatorItem {

	friend class CEDROOMRemoteConnectionLocator;

protected:

	TEDROOMInterfaceID m_InterfaceID;
	TEDROOMComponentID m_ComponentID;

	CEDROOMRemoteConnection * mp_RemoteConnection;

public:

	CEDROOMRemoteConnectionLocatorItem() {
		m_InterfaceID = 0;
		m_ComponentID = 0;
		mp_RemoteConnection = NULL;
	}

};


class CEDROOMRemoteConnectionLocator {

	friend class CEDROOMRemoteCommSAP;

protected:

	// ! Size of the table in CEDROOMRemoteConnectionLocatorItem's
	TEDROOMWord32 m_ItemTableSize;

	// ! Number of elements
	TEDROOMWord32 m_numElements;

	CEDROOMRemoteConnectionLocatorItem * mp_ItemTable;


	TEDROOMInt32 Compare(CEDROOMRemoteConnectionLocatorItem * item1
						, CEDROOMRemoteConnectionLocatorItem * item2);

	CEDROOMRemoteConnectionLocatorItem * SearchForItem(TEDROOMComponentID componentID
											, TEDROOMInterfaceID interfaceID);

public:

	CEDROOMRemoteConnectionLocator(CEDROOMRemoteConnectionLocatorItem * itemTable
			, TEDROOMWord32 size)
	{
		mp_ItemTable = itemTable;
		m_numElements = 0;
		m_ItemTableSize = size;
	}


	void OrderItems();

	CEDROOMRemoteConnection * SearchFor(TEDROOMComponentID componentID, TEDROOMInterfaceID interfaceID);

	TEDROOMInt32 AddItem(TEDROOMComponentID componentID
			, TEDROOMInterfaceID interfaceID
			, CEDROOMRemoteConnection * p_remoteConnection);

	TEDROOMInt32 RemoveItem(TEDROOMComponentID componentID
			, TEDROOMInterfaceID interfaceID);

};

class CEDROOMRemoteCommSAPMemory {

	friend class CEDROOMRemoteCommSAP;

protected:


	CEDROOMRemoteConnectionLocatorItem * mp_ItemTableMemory;

	TEDROOMUInt32 m_ItemTableMemorySize;

	CEDROOMMessagesPool 		m_MessagesPool;

public:

	void SetMemory(TEDROOMUInt32 messagesNumber,
			CEDROOMMessage * pMessagesMemory,
			TEDROOMBool *	pMessagesMarksMemory,
			CEDROOMRemoteConnectionLocatorItem * pItemTableMemory,
			TEDROOMUInt32 itemTableSize)
	{
		m_MessagesPool.SetMemory(messagesNumber, pMessagesMemory
							   , pMessagesMarksMemory);
		mp_ItemTableMemory = pItemTableMemory;
		m_ItemTableMemorySize = itemTableSize;
	}
};

class CEDROOMRemoteCommSAP{

	friend class CEDROOMRemoteTXChannel;
	friend class CEDROOMRemoteRXChannel;

protected:

	CEDROOMRemoteConnectionLocator m_RemoteConnectionLocator;

	//! Maximum number of connections handled by this CommSAP
	TEDROOMUInt32 m_MaxConnections;

	//! Message Pool Pointer
	CEDROOMMessagesPool 		* mp_MsgPool;

	//! Remote Comm SAP resources Mutex
	Pr_SemaphoreRec 			m_Mutex;

	virtual void DeliverMsg(CEDROOMRemoteTXChannel * channel, CEDROOMMessage * message) = 0;

public:

	/*!
    * \brief Connect the components interfaces
    * \param interfaceComp1 reference to component 1 interface
    * \param interfaceComp2 reference to component 2 interface
    * \param connection reference to the object that handles the connection
    * \param comp1ToComp2SignalTranslator component1 to component2 signal
    * 			translator
    * \param comp2ToComp1SignalTranslator component2 to component1 signal
    * 			translator
    */
	void Connect(CEDROOMInterface & interface
				, TEDROOMComponentID destinationComponentID
				, TEDROOMInterfaceID destInterfaceID
				, CEDROOMRemoteConnection * remoteConnection
				, CEDROOMRemoteConnectionInfo * pConnectionInfo
				, pFunSerializeData (fGetSerializeFun) (TEDROOMSignal)
				, pFunGetInformation funGetInformation
			    , TEDROOMSignal (senderToNetworkTranslator) (TEDROOMSignal)
			    , TEDROOMSignal (networkToReceiverTranslator) (TEDROOMSignal));


	CEDROOMRemoteCommSAP(TEDROOMUInt32 maxConnections,
			CEDROOMRemoteCommSAPMemory * pRemoteCommSAPMemory);

#ifdef _EDROOM_IS_DEBUG_

	/*!
    * \brief register the Interface
    * \param id interface local identifier
    * \param interface reference to the interface
    * \param pComponent pointer to the component
    * \param interfaceName interfaceName
    * \return value!=0 if there is an error
    */
	TEDROOMInt32 RegisterInterface(TEDROOMInterfaceID id
						, CEDROOMInterface & interface
						, CEDROOMComponent* pComponent
						, const char * interfaceName
						);

#else

	/*!
    * \brief register the Interface
    * \param id interface local identifier
    * \param interface reference to the interface
    * \param pComponent pointer to the component
    * \return a value !=0 if there is an error
    */
	TEDROOMInt32 RegisterInterface( TEDROOMInterfaceID id
						, CEDROOMInterface & interface
						, CEDROOMComponent* pComponent);
#endif


#ifdef _EDROOM_SYSTEM_CLOSE

	/*!
    * \brief Deregister a components interface
    * \param interface reference to component interface
    * \return a value !=0 if there is an error
    */
	TEDROOMInt32 DeregisterInterface(CEDROOMInterface & interface);


#endif

	//! Starts the communication services
    virtual TEDROOMWord32 initService (void) = 0;

    //! Ends the communication services
    virtual TEDROOMWord32 endService (void) = 0;

    virtual ~CEDROOMRemoteCommSAP() {};

};

class CEDROOMPackage {

public:

	virtual void SetSenderInterfaceID(TEDROOMInterfaceID senderInterfaceID) = 0;
	virtual TEDROOMInterfaceID GetSenderInterfaceID(void) = 0;
	virtual void SetDestinationInterfaceID(TEDROOMInterfaceID destinationInterfaceID) = 0;
	virtual TEDROOMInterfaceID GetDestinationInterfaceID(void) = 0;

	virtual void SetSenderComponentID(TEDROOMComponentID senderComponentID) = 0;
	virtual TEDROOMComponentID GetSenderComponentID(void) = 0;
	virtual void SetDestinationComponentID(TEDROOMComponentID destinationInterfaceID) = 0;
	virtual TEDROOMComponentID GetDestinationComponentID(void) = 0;

	virtual void SetSignal(TEDROOMSignal signal) = 0;
	virtual TEDROOMSignal GetSignal(void) = 0;

	virtual void SetMessageType(TEDROOMMessageType type) = 0;
	virtual TEDROOMMessageType GetMessageType(void) = 0;

	virtual void SetPriority(TEDROOMPriority priority) = 0;
	virtual TEDROOMPriority GetPriority(void) = 0;

	virtual void SetTimeStamp(TEDROOMWord32 time) = 0;
	virtual TEDROOMWord32 GetTimeStamp(void) = 0;

	virtual void SetDataSize(TEDROOMWord32 dataSize) = 0;
	virtual TEDROOMWord32 GetDataSize(void) = 0;

	virtual void * GetpRawData(void) = 0;

	virtual void * GetpRawPackage(void) = 0;
	virtual TEDROOMWord32 GetRawPackageSize(void) = 0;

	virtual void SetMemory(TEDROOMByte * buffer) = 0;
};

class CEDROOMPackageFragment {

public:

	virtual void SetFirst(void) = 0;
	virtual void SetLast(void) = 0;
	virtual void SetIndex(TEDROOMUInt32 index) = 0;

	virtual TEDROOMBool IsFirst(void) = 0;
	virtual TEDROOMBool IsLast(void) = 0;
	virtual TEDROOMUInt32 GetIndex(void) = 0;

	virtual void SetFragmentSize(TEDROOMWord32 fragmentSize) = 0;
	virtual TEDROOMWord32 GetFragmentSize(void) = 0;

	virtual void SetMemory(TEDROOMByte * buffer) = 0;

};

class CEDROOMFragmentedPackage : public CEDROOMPackage {

public:

	// TODO: PutFragment should return if the operation is OK
	virtual void PutFragment(CEDROOMPackageFragment * fragment) = 0;
	virtual void GetFragment(CEDROOMPackageFragment * fragment) = 0;

	virtual void ResetFragmentIndex(void) = 0;
	virtual TEDROOMUInt32 GetFragmentIndex(void) = 0;

};

class CEDROOMFragmentedPackagesPool : public CEDROOMMemoryPool {

public:


	void SetMemory(TEDROOMUInt32 dimension
					, void * pMessagePool
  					, TEDROOMBool * pMemoryMarks
  					, TEDROOMUInt32 elementSize);

	CEDROOMFragmentedPackage * AllocData();

	~CEDROOMFragmentedPackagesPool(){};
};



class CEDROOMRegularRemoteCommSAPMemory : public CEDROOMRemoteCommSAPMemory {

public:

	TEDROOMByte * mp_OutBufferPackageMemory;
	TEDROOMUInt32 m_OutBufferPackageMemorySize;

	TEDROOMByte * mp_InBufferPackageMemory;
	TEDROOMUInt32 m_InBufferPackageMemorySize;

	//! queue nodes pool
	CEDROOMQueue::CEDROOMQueueNodesPool  	m_QueueNodesPool;
	//! pointer to queue heads
	CEDROOMQueue::CQueueHead        * 		mp_QueueHeads;

	void SetMemory(TEDROOMUInt32 messagesNumber,
			CEDROOMMessage * pMessagesMemory,
			TEDROOMBool *	pMessagesMarksMemory,
			CEDROOMRemoteConnectionLocatorItem * pItemTableMemory,
			TEDROOMUInt32 itemTableSize,
			CEDROOMQueue::CQueueNode	* 	pQueueNodesMemory,
			TEDROOMBool 				*	pQueueNodesMarksMemory,
			CEDROOMQueue::CQueueHead 	*	pQueueHeadsMemory,
			TEDROOMByte * pOutBufferPackageMemory,
			TEDROOMUInt32 outBufferPackageMemorySize,
			TEDROOMByte * pInBufferPackageMemory,
			TEDROOMUInt32 inBufferPackageMemorySize)
	{
		CEDROOMRemoteCommSAPMemory::SetMemory(messagesNumber,
				pMessagesMemory,
				pMessagesMarksMemory,
				pItemTableMemory,
				itemTableSize);

		m_QueueNodesPool.SetMemory(messagesNumber, pQueueNodesMemory
												, pQueueNodesMarksMemory);

		mp_QueueHeads = pQueueHeadsMemory;

		mp_OutBufferPackageMemory = pOutBufferPackageMemory;
		m_OutBufferPackageMemorySize = outBufferPackageMemorySize;

		mp_InBufferPackageMemory = pInBufferPackageMemory;
		m_InBufferPackageMemorySize = inBufferPackageMemorySize;
	}



};

class CEDROOMRegularRemoteCommSAP : public CEDROOMRemoteCommSAP {

protected:

	TEDROOMUInt32 m_MaxNumberOfPriorities;

	CEDROOMPackage * mp_OutBufferPackage;
	TEDROOMUInt32 mp_OutBufferPackageMaxSize;

	CEDROOMPackage * mp_InBufferPackage;
	TEDROOMUInt32 mp_InBufferPackageMaxSize;

	CEDROOMRemoteConnectionInfo * mp_RXConnectionInfo;

    CEDROOMQueue m_MsgQueueTX; // Msg queue for TX Task

    Pr_Task m_CommTXTask;

    Pr_Task m_CommRXTask;

    void DeliverMsg(CEDROOMRemoteTXChannel * channel, CEDROOMMessage * message);

    /** \brief Function which the CommTask executes */
    static Pr_TaskRV_t EDROOMfunTXComm(Pr_TaskP_t);
    /** \brief Function which the CommTask executes */
    static Pr_TaskRV_t EDROOMfunRXComm(Pr_TaskP_t);

    /** \brief This function initializes the receiving phase of the remote
     * communication */
    virtual TEDROOMInt32 initReceive (void) = 0;
    virtual TEDROOMInt32 initSend (void) = 0;

    /** \brief Receives a Package */
    virtual TEDROOMInt32 receive (CEDROOMPackage *, TEDROOMUInt32) = 0;

    virtual TEDROOMInt32 send (CEDROOMRemoteConnectionInfo *,
                               CEDROOMPackage *) = 0;

    /** \brief Ends the receiving phase of the remote communication */
    virtual TEDROOMInt32 closeReceive (void) = 0;


public:

	//! Starts the communication services
    TEDROOMWord32 initService (void);

    //! Ends the communication services
    TEDROOMWord32 endService (void);

    CEDROOMRegularRemoteCommSAP(TEDROOMUInt32 maxConnections,
			TEDROOMUInt32 maxNumberOfPriorities,
			TEDROOMUInt32 maxNumberOfMessages,
			TEDROOMUInt32 commTasksStackSize,
			CEDROOMPackage * pInBufferPackage,
			CEDROOMPackage * pOutBufferPackage,
			CEDROOMRemoteConnectionInfo * remoteConnectionInfo,
			CEDROOMRegularRemoteCommSAPMemory * commSAPMemory);

    ~ CEDROOMRegularRemoteCommSAP() {};
};

class CEDROOMFragmentedRemoteCommSAPMemory : public CEDROOMRemoteCommSAPMemory {

public:

	CEDROOMFragmentedPackage *** mp_InNodePriorityPackages;
	CEDROOMFragmentedPackage ** mp_OutPriorityPackages;
	CEDROOMPackageFragment * mp_InFragment;
	CEDROOMPackageFragment * mp_OutFragment;

	//! queue nodes pool
	CEDROOMQueue::CEDROOMQueueNodesPool  	m_QueueNodesPool;
	//! pointer to queue heads
	CEDROOMQueue::CQueueHead        * 		mp_QueueHeads;

	CEDROOMFragmentedPackagesPool m_OutPackagesPool;
	CEDROOMFragmentedPackagesPool m_InPackagesPool;

	void SetMemory(TEDROOMUInt32 messagesNumber,
			CEDROOMMessage * pMessagesMemory,
			TEDROOMBool *	pMessagesMarksMemory,
			CEDROOMRemoteConnectionLocatorItem * pItemTableMemory,
			TEDROOMUInt32 itemTableSize,
			CEDROOMQueue::CQueueNode	* 	pQueueNodesMemory,
			TEDROOMBool 				*	pQueueNodesMarksMemory,
			TEDROOMUInt32	QueueNodesNumer,
			CEDROOMQueue::CQueueHead 	*	pQueueHeadsMemory,
			CEDROOMFragmentedPackage ** pOutPackages,
			void * pOutPriorityPackages,
			TEDROOMUInt32 outBufferPackageSize,
			TEDROOMUInt32 outBufferPackageNum,
			TEDROOMBool * pOutPackageMarksMemory,
			CEDROOMFragmentedPackage *** pInPackages,
			void * pInNodePriorityPackages,
			TEDROOMUInt32 inBufferPackageSize,
			TEDROOMUInt32 inBufferPackageNum,
			TEDROOMBool * pInPackageMarksMemory,
			CEDROOMPackageFragment * pOutFragment,
			CEDROOMPackageFragment * pInFragment)
	{
		CEDROOMRemoteCommSAPMemory::SetMemory(messagesNumber,
				pMessagesMemory,
				pMessagesMarksMemory,
				pItemTableMemory,
				itemTableSize);

		m_OutPackagesPool.SetMemory(outBufferPackageNum,
									pOutPriorityPackages,
									pOutPackageMarksMemory,
									outBufferPackageSize);
		m_InPackagesPool.SetMemory(inBufferPackageNum,
									pInNodePriorityPackages,
									pInPackageMarksMemory,
									inBufferPackageSize);
		mp_QueueHeads = pQueueHeadsMemory;
		m_QueueNodesPool.SetMemory(QueueNodesNumer, pQueueNodesMemory,pQueueNodesMarksMemory);

		mp_InNodePriorityPackages = pInPackages;
		//DEBUG("InNodePriorityPackages starts in %p", (void *)pInPackages);
		mp_OutPriorityPackages = pOutPackages;
		//DEBUG("OutPriorityPackages starts in %p", (void *)pOutPackages);
		mp_InFragment = pInFragment;
		mp_OutFragment = pOutFragment;
	}



};

class CEDROOMFragmentedRemoteCommSAP : public CEDROOMRemoteCommSAP {

protected:

	TEDROOMUInt32 m_MaxNumberOfConnections;
	TEDROOMUInt32 m_MaxNumberOfPriorities;

	CEDROOMFragmentedPackage ** mp_OutPriorityPackages;

	CEDROOMFragmentedPackage *** mp_InNodePriorityPackages;

	CEDROOMPackageFragment * mp_InPackageFragment;
	CEDROOMPackageFragment * mp_OutPackageFragment;

	CEDROOMFragmentedPackagesPool * mp_OutPackagesPool;
	CEDROOMFragmentedPackagesPool * mp_InPackagesPool;

	CEDROOMRemoteConnectionInfo * mp_LocalConnectionInfo;
	CEDROOMRemoteConnectionInfo * mp_RemoteConnectionInfo;

	pFunGetConnectionID mp_GetConnectionIDFun;

    CEDROOMQueue m_MsgQueueTX; // Msg queue for TX Task

    Pr_Task m_CommTXTask;

    Pr_Task m_CommRXTask;

    void DeliverMsg(CEDROOMRemoteTXChannel * channel, CEDROOMMessage * message);

    /** \brief Function which the CommTask executes */
    static Pr_TaskRV_t EDROOMfunTXComm(Pr_TaskP_t);
    /** \brief Function which the CommTask executes */
    static Pr_TaskRV_t EDROOMfunRXComm(Pr_TaskP_t);

    /** \brief This function initializes the receiving phase of the remote
     * communication */
    virtual TEDROOMInt32 initReceive (void) = 0;
    virtual TEDROOMInt32 initSend (void) = 0;

    /** \brief Receives a Package
     *
     * \param fragment Memory where the fragment will be stored
     * \param size Allowed maximum size of the fragment
     * \param senderInfo Information of the node that sent the package
     * \param priority Priority of the package */
    virtual TEDROOMInt32 receive (CEDROOMPackageFragment * fragment,
    							  CEDROOMRemoteConnectionInfo * senderInfo,
    							  TEDROOMPriority * priority) = 0;

    virtual TEDROOMInt32 send (CEDROOMRemoteConnectionInfo *,
    						   CEDROOMPackage * package,
                               CEDROOMPackageFragment * fragment) = 0;

    /** \brief Ends the receiving phase of the remote communication */
    virtual TEDROOMInt32 closeReceive (void) = 0;


public:

	//! Starts the communication services
    TEDROOMWord32 initService (void);

    //! Ends the communication services
    TEDROOMWord32 endService (void);

    CEDROOMFragmentedRemoteCommSAP(TEDROOMUInt32 maxConnections,
			TEDROOMUInt32 maxNumberOfPriorities,
			TEDROOMUInt32 maxNumberOfMessages,
			TEDROOMUInt32 commTasksStackSize,
			CEDROOMRemoteConnectionInfo * localConnectionInfo,
			CEDROOMRemoteConnectionInfo * remoteConnectionInfo,
			pFunGetConnectionID getConnectionIDFun,
			CEDROOMFragmentedRemoteCommSAPMemory * commSAPMemory);

    ~ CEDROOMFragmentedRemoteCommSAP() {};
};

#endif /*EDROOMREMOTECOMM_H_*/


/*!
 * \brief edroomcomponent header (edroom services library) 
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-03-04 09:08:17 $
 * \Version $Revision: 1.1.2.2 $
 * 
 * $Log: edroomcomponent.h,v $
 * Revision 1.1.2.2  2010-03-04 09:08:17  opolo
 * Changed the names of the attributes
 *
 * Revision 1.1.2.1  2010-02-15 10:08:11  opolo
 * actualizados los nombres de los archivos y servicios
 *
 */


#ifndef _EDROOM_COMPONENT_H
#define _EDROOM_COMPONENT_H


 
//************************************************************************
/*!
 * \class CEDROOMComponent
 * \brief This class implements an component on an EDROOM Model .
 *
 * \author Oscar Rodriguez Polo
 */
//************************************************************************


class CEDROOMComponent{

	friend class CEDROOMLocalCommSAP;
	friend class CEDROOMRemoteCommSAP;
	friend class CEDROOMMyCCMCommSAP;
	friend class CEDROOMTimingSAP;
	friend class CEDROOMLocalTXChannel;
	friend class CEDROOMRemoteTXChannel;
	friend class CEDROOMRemoteRXChannel;
	friend class CEDROOMQueue;
	friend class CEDROOMIRQInterface;

#ifdef _EDROOM_HAND_EXCEP_
	friend class CEDROOMExceptionSAP;
#endif

	//*************************************************************************
		//Protected Attributes
	//*************************************************************************


protected:


	// !Component's global ID
	TEDROOMComponentID		m_ComponentID;

	//! Component resources Mutex 
	Pr_SemaphoreRec 			m_Mutex; 

	//! Message Back in a Synchronous Communication
	CEDROOMMessage 				m_MessageBack;  
	
	//! Message Out in a Synchronous Communication
	CEDROOMSynchrMessage 		m_SynchrMsgOut;    
	
	//!	Synchronous Messages Pool 
	CEDROOMSynchrMessagesPool 	m_SynchrMsgPool; 


	//! Message Pool Pointer
	CEDROOMMessagesPool 		*mp_MsgPool;  
	
	
 	//!Maximum Number of User Messages in Component Queue.  
 	int 						m_MaxNumMsgs;   


 	//!Number of Different Message Priorities that component handles.  
	unsigned 					m_NumMsgPrio;  
	

	// !Conections number of this component.
	unsigned 					m_NumConections;  
	
	// !Component Task 
	Pr_Task 					m_ComponentTask;

	// !Pointer to Component Task 
	Pr_Task 				*	mp_ComponentTask;

	//! Component Messages Queue 
	CEDROOMQueue 				m_MsgQueue;  


#ifdef __EDROOMSL_2010
 	//! Pointer to the array of IRQInterfaces pointers
	CEDROOMIRQInterface 	**	mpp_IRQInterfaces;
	
	//! Pointer to the array of TimingInterfaces pointers
	CEDROOMTimingInterface 	**	mpp_TimingInterfaces;
#endif	



#ifndef _EDROOM_NO_INHERIT_MSG

	//! Component that is locking me in a synchronous comunication
    CEDROOMComponent *			mp_ComponentIsLockingMe; 

//*************************************************************************
		//Protected Methods
//*************************************************************************


	/*!
   	* Manage priority inheritance in Send Message primitive
   	* \param priority inherit priority 
    */

    void PrioInheritanceInSendMsg( TEDROOMPriority  priority); 


	/*!
   	* Manage priority inheritance in Invoke Message primitive, Check if there 
   	* is Interblock
   	* \param component component that invokes
   	* \param priority inherit priority 
    */
    bool PrioInheritanceInInvokeMsg( CEDROOMComponent * component, 
    								TEDROOMPriority  priority); 

#endif


//*************************************************************************
		//Protected Methods
//*************************************************************************

	/*!
   	* Code that implements the component task 
    */
#ifdef _EDROOM_TASK_POSIX_

    static void * EDROOMComponentTask(void * paramDumy);

#else
    static Pr_TaskRV_t EDROOMComponentTask(Pr_TaskP_t);
#endif


	//! virtual method that will implement the component behaviour 
	virtual void EDROOMBehaviour()=0; 


	#ifdef _EDROOM_SYSTEM_CLOSE

	//! virtual free memory component 
	void FreeMem(); 					

	//!  is true when component behaviour is finished
	bool m_IsFinished; 

	#endif


//*************************************************************************
		//Public Attributes
//*************************************************************************


public:

	#ifdef _EDROOM_IS_DEBUG_

	//!  EDROOM name
	const char * const EDROOMName;
	
	/*!
   	* Trace Transition in debug mode
   	* \param transId transiditon identifier
   	* \param signal  transition trigger msg signal
    */
	void EDROOMTraceTrans(TEDROOMTransId & transId, TEDROOMSignal signal);

	/**
     *\brief Trace State Entry in debug mode
     */
    void EDROOMTraceStateEntry();

	/**
     *\brief Trace State Exit in debug mode
     */
	void EDROOMTraceStateExit();

	#endif


public:


	/** current message that component handles after it has been got
	 * from the component message queue. The memory related with the message
	 * is freed after message is handled
	 */
	CEDROOMMessage *Msg;   

	//! message back in a synchronous communication.  
	CEDROOMMessage *MsgBack;   


#ifdef _EDROOM_HAND_EXCEP_

	//! message that is throw because of an exception.  
	CEDROOMMessage *MsgExc;

	//! flag that is true when new message is thrown   
	bool m_IsNewException;

#endif




	/** Method that gets new message from the component queue and it is pointed
	 * by Msg.
	 *  Previou smessage pointed by Msg is freed. 
	 */
	void EDROOMNewMsg();   
								

#ifdef _EDROOM_HAND_EXCEP_

	/** Method that gets new message from the component queue and it is pointed
	 * by Msg when exceptions are enable.
	 *  Previou smessage pointed by Msg is freed. 
	 */
	void EDROOMNewMsgWithExc();   

#endif




	#ifdef _EDROOM_IS_DEBUG_

	/** Component constructor in Debug mode 
	 * \param name pointer to component name
	 * \param containerName pointer to component container name 
	 * \param prioNum number of different message priorities that component 
	 * 			handles
	 * \param connectNum  number of connections that component handles
	 * \param maxNumMsg maximum number of messages
	 * \param taskPriority priority when component task is created
	 * \param stack component task stack
	 * \param pComponentMemory pointer to component memory 
	 */

	CEDROOMComponent(				const char * const name,
									TEDROOMComponentID componentID,
									unsigned prioNum,
									unsigned connectNum, 
									int maxNumMsg, 
									TEDROOMPriority taskPriority,
									unsigned stack,
									CEDROOMComponentMemory * pComponentMemory);


	#else

	/** Component constructor in Debug mode 
	 * \param prioNum number of different message priorities that component 
	 * 			handles
	 * \param connectNum  number of connections that component handles
	 * \param maxNumMsg maximum number of messages
	 * \param taskPriority priority when component task is created
	 * \param stack component task stack
	 * \param pComponentMemory pointer to component memory 
	 */

	CEDROOMComponent(				TEDROOMComponentID componentID,
									unsigned prioNum,
									unsigned connectNum, 
									int maxNumMsg, 
									TEDROOMPriority taskPriority,
									unsigned stack,
									CEDROOMComponentMemory * pComponentMemory);



	#endif



	/** Component Start
	 * \param creates the Component task from virtual EDROOMBehaviour method
	 * \return 0
	 */
	int EDROOMStart ();


	
	#ifdef _EDROOM_SYSTEM_CLOSE

	/** Virtual method that checks if component is finished 
	 * \return true if component is finished
	 */
	virtual  TEDROOMBool EDROOMIsComponentFinished();

	#endif
	
	/** virtual Component destructor, only for avoid warnings
	 */
	virtual ~CEDROOMComponent();


	/** method that forces Component destruction
	 */
	void EDROOMDestroy();


};

//************************************************************************
/*!
 * \class CEDROOMComponentMemory
 * \brief This class implements the component memory on an EDROOM Model.
 *
 * \author Oscar Rodriguez Polo
 */
//************************************************************************

class CEDROOMComponentMemory{


	friend class CEDROOMComponent;
	friend class CEDROOMQueue;
	friend class CEDROOMTimingSAP;

	protected:

	//! messages pool 
	CEDROOMMessagesPool  					m_MessagesPool;
	//! queue nodes pool 
	CEDROOMQueue::CEDROOMQueueNodesPool  	m_QueueNodesPool;
	//! pointer to queue heads 
	CEDROOMQueue::CQueueHead        * 		mp_QueueHeads;

#ifdef __EDROOMSL_2010				
	
	//! Pointer to the array of TimingInterfaces pointers
	CEDROOMIRQInterface ** mpp_IRQInterfaces;
	
	//! Pointer to the array of TimingInterfaces pointers
	CEDROOMTimingInterface ** mpp_TimingInterfaces;
	
#endif	
 	

	/** Set Memory
	 * \param messagesNumber Messages number
	 * \param pMessagesMemory  pointer to connections memory
	 * \param pMessagesMarksMemory pointer to connections used marks memory 
	 * \param pQueueNodesMemory  queue nodes memory
	 * \param pQueueNodesMarksMemory queue nodes used marks memory 
	 * \param pQueueHeadsMemory queue heads memory 
	 */

	void SetMemory(		TEDROOMUInt32 					messagesNumber,
						CEDROOMMessage  			* 	pMessagesMemory,
						TEDROOMBool 				*	pMessagesMarksMemory,
						CEDROOMQueue::CQueueNode	* 	pQueueNodesMemory,
						TEDROOMBool 				*	pQueueNodesMarksMemory,
						CEDROOMQueue::CQueueHead 	*	pQueueHeadsMemory
				
#ifdef __EDROOMSL_2010				
						,CEDROOMIRQInterface 		**	ppIRQInterfaces
						,CEDROOMTimingInterface 	** 	ppTimingInterfaces);

#else
				);

#endif

};

#endif


/*!
 * \brief edroomexcept header (edroom services library) 
 * 
 * \author Oscar Rodrguez Polo
 * \date $Date: 2010-02-15 10:08:11 $
 * \Version $Revision: 1.1.4.3 $
 * 
 * $Log: edroomexcept.h,v $
 * Revision 1.1.4.3  2010-02-15 10:08:11  opolo
 * actualizados los nombres de los archivos y servicios
 *
 * Revision 1.1.4.2  2006/10/18 18:31:51  opolo
 * Add Log
 *
 *
 * Revision 1.1.4.1  2006/10/18 18:07:20  opolo
 * *** empty log message ***
 * 
 */
 
#ifndef __EDROOM_ExceptionSAP_H
#define __EDROOM_ExceptionSAP_H

/*!
 * \class CEDROOMExceptionSAP
 * \brief Service access point for exceptions  
 * \author Oscar Rodriguez Polo
 */

#ifdef _EDROOM_HAND_EXCEP_

class CEDROOMExceptionSAP{  //tratamiento de excepciones

	public:

	//!Pointer to the component 
	CEDROOMComponent  *mp_Component;

	/*!
    * Constructor 
    * \param pComponent pointer to the component that requires the SAP 
    */
	CEDROOMExceptionSAP(CEDROOMComponent *pComponent);

	
	/*!
    * new exception is thrown 
    */
	void NewException();

};

#endif

#endif
#endif
